<template>
  <div class="caseManage">
    <el-tabs v-model="activeName" type="card" class="elTabs">
      <el-tab-pane name="first">
        <div slot="label" class="pageHeader">案件趋势</div>
      </el-tab-pane>
    </el-tabs>

    <div class="container">
      <!-- 搜索查询 -->
      <div class="searchBar" v-show="showSearch">
        <div class="searchForm">
          <el-form
            :model="queryParams"
            ref="queryForm"
            size="small"
            :inline="true"
            v-show="showSearch"
            label-width="68px"
          >
            <el-form-item label="年份" prop="trendYear">
              <el-date-picker
                clearable
                v-model="queryParams.trendYear"
                type="year"
                value-format="yyyy"
                placeholder="请选择年份"
                @keyup.enter.native="handleQuery"
              ></el-date-picker>
            </el-form-item>
          </el-form>
          <div class="searchButtons">
            <el-button class="searchButton" @click="handleQuery">搜索</el-button>
            <el-button class="resetButton" @click="resetQuery">重置</el-button>
          </div>
        </div>
      </div>
      <div
        class="addDeleteBar"
        v-if="
          checkPermi(['supervision:trend:add', 'supervision:trend:edit'])"
      >
        <el-button
          class="addButton"
          v-hasPermi="['supervision:trend:add']"
          @click.native="handleAdd"
        >
          <span class="plus">+</span>
          新增
        </el-button>
        <el-button
          @click="handleDelete"
          :class="!multiple ? 'deleteButton' : 'allDeleteButton'"
          :disabled="multiple"
          icon="el-icon-delete"
          v-hasPermi="['supervision:trend:remove']"
        >批量删除</el-button>
      </div>
      <div class="tableSelectArea">
        <div>
          <div class="iconInfo el-icon-info"></div>
          <span class="infoText">已选择</span>
          <span class="infoText infoActive" v-text="selectedNum"></span>
          <span class="infoText">项</span>
          <span class="infoButton" @click="clearSelect">清空</span>
        </div>
        <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
      </div>
      <div class="table">
        <el-table
          v-loading="loading"
          :data="trendList"
          @selection-change="handleSelectionChange"
          ref="multipleTable"
          class="tableArea"
        >
          <el-table-column type="selection" width="55" align="center" />
          <el-table-column label="年份" align="center" prop="trendYear" />
          <el-table-column label="立案数(件)" align="center" prop="filCase" />
          <el-table-column label="涉案总金额(元)" align="center" prop="caseAmount" />
          <el-table-column label="涉案人数(人)" align="center" prop="casePeoples" />
          <el-table-column
            label="操作"
            width="200px"
            fixed="right"
            align="left"
          >
          <template slot-scope="scope">
              <div class="tableButtonArea">
                <el-button
                 type="text"
                  class="operationButton"
                @click="handleDetail(scope.row)"
              >详情</el-button>
              <el-button
                type="text"
                  class="operationButton"
                @click="handleUpdate(scope.row)"
                v-hasPermi="['supervision:trend:edit']"
              >修改</el-button>
              <el-button
                 type="text"
                  class="operationButton"
                @click="handleDelete(scope.row)"
                v-hasPermi="['supervision:trend:remove']"
              >删除</el-button>
              </div>
            </template>
          </el-table-column>


          <!-- <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
            <template slot-scope="scope">

            </template>
          </el-table-column> -->
        </el-table>
      </div>
      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </div>
    <caseTrendModal
      ref="caseTrendModal"
      :modalType.sync="modalType"
      :id="id"
      @fatherMethod="fatherMethod"
    ></caseTrendModal>
    <caseDetailModal :detailId.sync="detailId"></caseDetailModal>
  </div>
</template>

<script>
import { MODALTYPE } from "@/utils/variable";
import { checkPermi } from "@/utils/permission";
import { fatherMethod } from "@/utils/commonMethods";
import caseTrendModal from "./component/trendManageModal.vue";
import caseDetailModal from "./component/trendDetailModal.vue";
import {
  listTrend,
  getTrend,
  delTrend,
  addTrend,
  updateTrend,
} from "@/api/caseManage/caseStage/trend";
export default {
  dicts: ["case_state"],
  name: "Trend",
  components: { caseTrendModal, caseDetailModal },
  data() {
    return {
      selectedNum: 0,
      activeName: "first",
      modalType: "",
      id: 0,
      //详情页Id
      detailId: 0,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 案件趋势表格数据
      trendList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      openInfo: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        trendYear: null,
      },
      // 表单参数
      form: {},
      formInfo: {},
      // 表单校验
      rules: {
        trendYear: [
          { required: true, message: "年份不能为空", trigger: "blur" },
        ],
        filCase: [
          { required: true, message: "立案数不能为空", trigger: "blur" },
        ],
        caseAmount: [
          { required: true, message: "涉案总金额不能为空", trigger: "blur" },
        ],
        casePeoples: [
          { required: true, message: "涉案人数不能为空", trigger: "blur" },
        ],
      },
    };
  },
  created() {
    this.getList();
  },
  computed: {
  },
  methods: {
    checkPermi,
    fatherMethod,
    /** 详情按钮操作 */
    handleDetail(row) {
      this.detailId = row.id;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.modalType = MODALTYPE["新增"];
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.modalType = MODALTYPE["修改"];
      this.id = row.id;
    },
    //清空列表选择
    clearSelect() {
      this.$refs.multipleTable.clearSelection();
    },
    /** 查询案件趋势列表 */
    getList() {
      this.loading = true;
      listTrend(this.queryParams).then((response) => {
        this.trendList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        trendYear: null,
        filCase: null,
        caseAmount: null,
        casePeoples: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        isDelect: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.selectedNum = selection.length;
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 详情关闭按钮操作 */
    cancelInfo() {
      this.openInfo = false;
      this.formInfo = {};
      this.resetForm("formInfo");
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.id != null) {
            updateTrend(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addTrend(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      let num = this.selectedNum;
      if (row.id) {
        num = 1;
      }
      this.$modal
        .confirm("'是否确认删除" + num + "条数据'")
        .then(function () {
          return delTrend(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "supervision/trend/export",
        {
          ...this.queryParams,
        },
        `trend_${new Date().getTime()}.xlsx`
      );
    },
  },
};
</script>
<style lang="scss" scoped>
@import "../../../assets/styles/variables.scss";
.caseManage {
  height: 100%;
  .tableFooter {
    text-align: right;
    justify-content: flex-end;
    // margin-top: 25px;
    margin-right: 35px;
    // width: 100%;
    ::v-deep .btn-prev {
      color: #d4d3d3 !important;
      background-color: #fff;
      border: 1px solid #d4d3d3;
    }
    ::v-deep .btn-next {
      color: #d4d3d3 !important;
      background-color: #fff;
      border: 1px solid #d4d3d3;
    }
    ::v-deep .el-pager li {
      background-color: #fff;
      border: 1px solid #d4d3d3;
      font-size: 12px;
      font-family: $font-family;
      font-weight: 400;
      color: #5a5b5d;
    }
  }
  .el-form-item__label {
    font-family: $font-family;
    font-weight: $form-label-font-weight;
    font-size: $form-label-font-size;
    color: $form-label-color;
  }

  .el-input__inner {
    font-size: $form-content-font-size;
    font-family: $font-family;
    font-weight: $form-label-font-weight;
    // color: #AEAFB0;
  }
}
.input {
  width: 150px;
}
::v-deep .el-tabs--card .el-tabs__header {
  background-color: #e4e7ed;
}
::v-deep.el-tabs--card .el-tabs__header .el-tabs__item {
  border-radius: 10px solid black;
  background-color: #fff;
  font-size: 14px;
  font-family: Microsoft YaHei;
  font-weight: 400;
  color: #053ef6;
  line-height: 48px;
  margin-top: 0;
}
</style>
